package com.ycx.ycxmybatismanagement.service.Impl;

import com.ycx.ycxmybatismanagement.dto.StudentCountDataDTO;
import com.ycx.ycxmybatismanagement.mapper.EmpMapper;
import com.ycx.ycxmybatismanagement.service.ReportService;
import com.ycx.ycxmybatismanagement.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public EmpJobValueListVo empJobData() {
        // 从数据库查
        List<JobValueVo> voList = empMapper.empJobValue();
            if (CollectionUtils.isEmpty(voList)) {
                return new EmpJobValueListVo();
            }
        List<String> jobList = voList.stream().map(JobValueVo::getJobName).collect(Collectors.toList());
        List<Integer> valueList = voList.stream().map(JobValueVo::getJobValue).collect(Collectors.toList());
             return new EmpJobValueListVo(jobList,valueList);
//            // 结果组装
//            List<String> jobList = new ArrayList<>();
//            List<Integer> dataList = new ArrayList<>();
//            for (JobValueVo jobValueVo : voList) {
//                String title = jobValueVo.getTitle();
//                Integer value = jobValueVo.getValue();
//                jobList.add(title);
//                dataList.add(value);
//            }
//            EmpJobDataVo vo = new EmpJobDataVo();
//            vo.setDataList(dataList);
//            vo.setJobList(jobList);
//            return vo;
//        }

    }

    @Override
    public List<EmpGenderVo> empGenderList() {
        List<EmpGenderVo> empGenderValue = empMapper.empGenderValue();

        return empGenderValue;
    }

    @Override
    public List<StudentDegreeDataVO> studentDegreeData() {
        List<StudentDegreeDataVO> studentDegreeDataList = empMapper.studentDegreeData();
        return studentDegreeDataList;
    }

    @Override
    public StudentCountDataVO studentCountData() {
      List<StudentCountDataDTO> clazzCountList =  empMapper.selectClazzList();
        List<String> clazzList = clazzCountList.stream().map(StudentCountDataDTO::getName).collect(Collectors.toList());
        List<Integer> dataList = clazzCountList.stream().map(StudentCountDataDTO::getValue).collect(Collectors.toList());

        return new StudentCountDataVO(clazzList,dataList);
    }
}

